import { isArray, isString } from './is';

// 新增按钮
const ADD_BUTTON = {
  id: 'add',
  text: '新增',
  iconName: 'button_add'
};
// 修改按钮
const UPDATE_BUTTON = {
  id: 'update',
  text: '修改',
  iconName: 'button_update'
};
// 删除按钮
const DELETE_BUTTON = {
  id: 'delete',
  text: '删除',
  iconName: 'button_delete'
};
// 审核按钮
const AUDIT_BUTTON = {
  id: 'audit',
  text: '审核',
  iconName: 'button_check'
};
const COUNTERSIGN_BUTTON = {
  id: 'countersign',
  text: '会签',
  iconName: 'button_issued'
};
// 批准按钮
const APPROVE_BUTTON = {
  id: 'approve',
  text: '批准',
  iconName: 'button_acceptance'
};
// 发布按钮
const RELEASE_BUTTON = {
  id: 'release',
  text: '发布',
  iconName: 'button_release'
};
// 流程列表按钮
const FLOWLIST_BUTTON = {
  id: 'flowList',
  text: '流程列表',
  iconName: 'flowButton'
};
// 导出按钮
const EXPORT_BUTTON = {
  id: 'export',
  text: '导出',
  iconName: 'button_export'
};
// 风险变更特殊按钮
// 时间变更
const TIMECHANGE_BUTTON = {
  id: 'timeChange',
  text: '时间变更',
  iconName: 'button_add'
};
// 风险等级变更
const RISKLEVELCHANGE_BUTTON = {
  id: 'riskLevelChange',
  text: '风险等级变更',
  iconName: 'button_input'
};
// 风险内容变更
const RISKINFOCHANGE_BUTTON = {
  id: 'riskInfoChange',
  text: '风险内容变更',
  iconName: 'button_issued'
};

const button = {
  ADD_BUTTON,
  UPDATE_BUTTON,
  DELETE_BUTTON,
  AUDIT_BUTTON,
  COUNTERSIGN_BUTTON,
  APPROVE_BUTTON,
  RELEASE_BUTTON,
  FLOWLIST_BUTTON,
  EXPORT_BUTTON,
  TIMECHANGE_BUTTON, // 时间变更
  RISKLEVELCHANGE_BUTTON, // 风险等级变更
  RISKINFOCHANGE_BUTTON // 风险内容变更
};
const buttonMap = new Map();
Object.values(button).forEach((item) => {
  buttonMap.set(item.id, item);
  buttonMap.set(item.text, item);
});
export function getActions(options) {
  if (!isString(options) && !isArray(options)) {
    throw new Error('只支持逗号分隔的字符串或者数组');
  }
  let _options = [];
  if (isString(options)) {
    _options = options.split(',');
  }
  if (isArray(options)) {
    _options = options;
  }
  const result = [];
  _options.forEach((item) => {
    if (!buttonMap.get(item)) {
      console.warn(`${item}按钮不存在`);
    } else {
      result.push(buttonMap.get(item));
    }
  });
  return result;
}
/** 使用示例
 * const actions = getActions('add,update,delete')
 * const actions = getActions(['add','update','delete'])
 * const actions =getActions('新增,修改,删除')
 * const actions = getActions(['新增','修改','删除'])
 * const actions = getActions('新增,update,删除')
 * const actions = getActions(['新增','update','删除'])
 *
 * actions // [ADD_BUTTON,UPDATE_BUTTON,DELETE_BUTTON]
 */
